package requetesHQL;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import configuration.HibernateUtil;

import metier.Propriete;

public class ProprieteHQL {
	
	public ProprieteHQL(){
		super();
	}
	
	public ArrayList<Propriete> requeteLesNbPremierePropriete(int nb){
		Session laSession = HibernateUtil.getSession();
		String requeteSelect = "FROM metier.Propriete";
		Query reqExecute = laSession.createQuery(requeteSelect);
		if(nb != -1) reqExecute.setMaxResults(nb); 
		List<Propriete> lesProprietes = reqExecute.list();
		return (ArrayList<Propriete>) lesProprietes;
	}
	
	public Propriete recupererPropriete(String ref){
		Session laSession = HibernateUtil.getSession();
		String requeteSelect = "FROM metier.Propriete WHERE refpropriete = "+ref;
		Query reqExecute = laSession.createQuery(requeteSelect);
		Propriete laPropriete = (Propriete) reqExecute.list().get(0);
		return laPropriete;
	}
	
	
}
